//
//  ViewWithButtonAndTitle.m
//  quanminzhekou
//
//  Created by zxl on 15/5/22.
//  Copyright (c) 2015年 zhongqinglongtu. All rights reserved.
//

#import "ViewWithButtonAndLable.h"

@interface ViewWithButtonAndLable ()
@property (nonatomic, strong) UIButton* btn;
@property (nonatomic, strong) UILabel* lab;
@end

@implementation ViewWithButtonAndLable

- (instancetype)initWithFrame:(CGRect)frame shareModel:(ShareModel*)model
{
    self = [super initWithFrame:frame];
    if (self) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn.frame = CGRectMake((CGRectGetWidth(frame) - 45) / 2.0, 0, 45, 45);
        [_btn setImage:[UIImage imageNamed:model.imgStrForBtnNormal] forState:UIControlStateNormal];
//        [_btn setImage:[UIImage imageNamed:model.imgStrForBtnHighlight] forState:UIControlStateHighlighted];
        [_btn addTarget:self action:@selector(onTapBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_btn];
        
        _lab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(_btn.frame) + 5, CGRectGetWidth(frame), CGRectGetHeight(frame) - CGRectGetHeight(_btn.frame) - 5)];
        _lab.backgroundColor = [UIColor clearColor];
        _lab.textColor = [UIColor blackColor];
        _lab.font = [UIFont systemFontOfSize:12];
        _lab.textAlignment = NSTextAlignmentCenter;
        _lab.text = model.titleStr;
        [self addSubview:_lab];
    }
    
    return self;
}

#pragma mark - 
- (void)onTapBtn:(UIButton*)btn {
    if (self.tapButtonHandler) {
        self.tapButtonHandler();
    }
}

@end
